package cn.itsource.test.sand.demo;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.UUID;

/**
 * @author : 张金铭
 * @description :
 * @create :2023-04-25 15:53:00
 */
public class TodoDemo {
        public static void main(String[] args) {
        String json = "{\n" +
                "    \"petition\": {\n" +
                "        \"petitionNumber\": \"2022020204\",\n" +
                "        \"title\": \"思明区张汉城\",\n" +
                "        \"content\": \"测试查询\",\n" +
                "        \"eventAddress\": \"思明区二里屯\",\n" +
                "        \"longitude\": 118.111111,\n" +
                "        \"latitude\": 24.222222,\n" +
                "        \"areaCode\": \"350203001011\",\n" +
                "        \"areaName\": \"思明区\",\n" +
                "        \"eventCategoryCode\": \"012123\",\n" +
                "        \"eventCategoryName\": \"测试数据\",\n" +
                "        \"sourcePid\": \"111\",\n" +
                "        \"complainant\": \"vit\",\n" +
                "        \"complainantTel\": \"1111111\",\n" +
                "        \"registerTime\": \"2022-01-01 22:00:11\",\n" +
                "        \"sourceSysCode\": \"ywtg\"\n" +
                "    },\n" +
                "    \"task\": {\n" +
                "        \"submitType\": \"01\",\n" +
                "        \"taskUrl\": \"http://192.168.1.210:8089\",\n" +
                "        \"sourceTaskId\": \"123465789\",\n" +
                "        \"sendOfficeId\": \"2131\",\n" +
                "        \"sendOfficeName\": \"ddd\",\n" +
                "        \"sendUserId\": \"1231\",\n" +
                "        \"sendUserName\": \"地方都是\"\n" +
                "    },\n" +
                "    \"handlers\": [\n" +
                "        {\n" +
                "            \"officeId\": \"1459841363562\",\n" +
                "            \"officeName\": \"思明区\",\n" +
                "            \"userId\": \"1009\",\n" +
                "            \"userName\": \"张汉城\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"supervise\": {\n" +
                "        \"itemCode\": \"11231\",\n" +
                "        \"deadline\": \"2023-09-01 11:00:22\",\n" +
                "        \"warningTime\": \"2023-04-25 11:00:22\",\n" +
                "        \"startTime\": \"2022-04-25 11:00:22\"\n" +
                "    }\n" +
                "}\n";


        String strTest = "{\n" +
                "\t\"task\": {\n" +
                "\t\t\"sendUserId\": \"984\",\n" +
                "\t\t\"sendOfficeId\": \"1459999990221\",\n" +
                "\t\t\"submitType\": \"00\",\n" +
                "\t\t\"taskUrl\": \"http://192.168.1.232:1199//#/detailInfo?id=402885d587bb166a0187bb1a1a640067&flowName=线索办理&packageName=公共安全&formId=402885d587bb166a0187bb1c6db300aa&workItemId=402885d587bb166a0187bb1c78c000b3\",\n" +
                "\t\t\"sourceTaskId\": \"402885d587bb166a0187bb1c6db300a1\",\n" +
                "\t\t\"sendOfficeName\": \"思明区\",\n" +
                "\t\t\"sendUserName\": \"郭美凤\"\n" +
                "\t},\n" +
                "\t\"handlers\": [],\n" +
                "\t\"petition\": {\n" +
                "\t\t\"eventAddress\": \"\",\n" +
                "\t\t\"sourceSysCode\": \"ywtg\",\n" +
                "\t\t\"registerTime\": 1682471263000,\n" +
                "\t\t\"latitude\": 0E-8,\n" +
                "\t\t\"petitionNumber\": \"202304260064\",\n" +
                "\t\t\"title\": \"ceshiyiwang\",\n" +
                "\t\t\"complainant\": \"\",\n" +
                "\t\t\"eventCategoryCode\": \"023019\",\n" +
                "\t\t\"eventCategoryName\": \"自然灾害风险隐患/地震灾害风险\",\n" +
                "\t\t\"areaCode\": \"350203001011\",\n" +
                "\t\t\"sourcePid\": \"402885d587bb166a0187bb1a1a6400s6\",\n" +
                "\t\t\"areaName\": \"厦门市思明区厦港街道下沃社区\",\n" +
                "\t\t\"complainantTel\": \"\",\n" +
                "\t\t\"longitude\": 0E-8\n" +
                "\t},\n" +
                "\t\"supervise\": [{\n" +
                "\t\t\"itemCode\": \"01\",\n" +
                "\t\t\"deadline\": 1682557815000,\n" +
                "\t\t\"warningtime\": 1682539815000,\n" +
                "\t\t\"starttime\": 1682471415000\n" +
                "\t}, {\n" +
                "\t\t\"itemcode\": \"02\",\n" +
                "\t\t\"deadline\": 1683076215000,\n" +
                "\t\t\"warningtime\": 1682989815000,\n" +
                "\t\t\"starttime\": 1682471415000\n" +
                "\t}, {\n" +
                "\t\t\"itemcode\": \"03\",\n" +
                "\t\t\"deadline\": 1686100215000,\n" +
                "\t\t\"warningtime\": 1685409015000,\n" +
                "\t\t\"starttime\": 1682471415000\n" +
                "\t}]\n" +
                "}";
        String uuid = UUID.randomUUID().toString();
        String time = String.valueOf(System.currentTimeMillis());
        String result2 = HttpRequest.post("http://localhost:99/open/getSign")
                .header("X-apiKey", "ywtg")//头信息，多个头信息多次调用此方法即可
                .header("X-nonce",uuid)
                .header("X-timestamp",time)
                .body(strTest).execute().body();
        System.out.println(time);
        Object data = JSONObject.parseObject(result2).get("data");
        String str = JSON.toJSONString(data);
        System.out.println(str);
        Map map = JSON.parseObject(str, Map.class);
        String sign = String.valueOf(map.get("sign"));

        String result3 = HttpRequest.post("http://localhost:99/open/PetitionCollect")
                .header("X-apiKey", "ywtg")//头信息，多个头信息多次调用此方法即可
                .header("X-nonce",uuid)
                .header("X-timestamp",time)
                .header("X-sign",sign)
                .body(strTest).execute().body();
        System.out.println(result3);
    }
}
